define('pc/js/mod/ucenter/vue-account-safe', [
    'utils/fetchEnhancer'], (fetch) => {

const VueAccountSafe = {
    props: ['strUid'],
    data: function() {
        return {
            old: '',
            password: '',
            confirming: ''
        }
    },
    methods: {
        doEdit: function(e) {
            let btn = e.target;

            if('' === this.password) {
                XUI.toast.error('密码不能为空');
                return;
            }
            if(this.password !== this.confirming) {
                XUI.toast.error('两次密码不一致');
                return;
            }

            btn.disabled = true;
            fetch('/api/account/editpwdlogin', {
                method: 'POST',
                body: 'password=' + encodeURIComponent(this.password)
                    + '&confirming=' + encodeURIComponent(this.confirming)
                    + '&old=' + encodeURIComponent(this.old)
            }).then((res) => {
                btn.disabled = false;

                if(0 === res.status) {
                    this.old = '';
                    this.password = '';
                    this.confirming = '';
                    XUI.toast.success('修改成功');

                } else if(200002 === res.status) {
                    XUI.toast.error('无权限 ' + res.status);

                } else {
                    XUI.toast.error('修改失败 ' + res.status);
                }
            });
        }
    },
    template:
`<div>
    <h2 class="uc-itemtitle">账号安全</h2>
    <div class="uc-content-wrapper">
        <div class="uc-form-item">
            <label class="uc-form-label">原密码</label>
            <div class="uc-form-control">
                <input v-model="old" type="password" class="x-input" maxlength="20">
                <a style="margin-left: 10px;" target="_blank" href="/forget">忘记密码</a>
            </div>
        </div>
        <div class="uc-form-item">
            <label class="uc-form-label">新密码</label>
            <div class="uc-form-control">
                <input v-model="password" type="password" class="x-input" maxlength="20">
            </div>
        </div>
        <div class="uc-form-item">
            <label class="uc-form-label">确认密码</label>
            <div class="uc-form-control">
                <input v-model="confirming" type="password" class="x-input" maxlength="20">
            </div>
        </div>
        <div class="uc-form-item">
            <label class="uc-form-label">&nbsp;</label>
            <div class="uc-form-control">
                <button v-on:click="doEdit" type="button" class="x-btn">保存</button>
            </div>
        </div>
    </div>
</div>`
};

return VueAccountSafe;

});
